package com.uft.model.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.uft.controller.ServerController;
import com.uft.model.entity.DPProfile;
import com.uft.model.entity.DPRuntime;
import com.uft.model.entity.Profile;
import com.uft.model.entity.Server;

@Repository
public class DPProfileDAO {
	@PersistenceContext private EntityManager em;
	private  static Logger  logger = Logger.getLogger(DPProfileDAO.class);
	
	public List<DPProfile> getDPProfileList() {
		// TODO Auto-generated method stub
		logger.info("Get all the list");
		TypedQuery<DPProfile> query = em.createQuery(
		           "SELECT p FROM DPProfile p ", DPProfile.class);
		return query.getResultList();	
	}
	
	public DPProfile getDPProfileId(int id){
			logger.info("Get DP Profile: "+id);
			DPProfile dpProfile=em.find(DPProfile.class, id);
		   return dpProfile;
	 }
	 @SuppressWarnings("unchecked")
	   public List<DPRuntime> getDPRuntimeByStartEnd(String dpName, Date startTime, Date endTime) {
		  return  em.createNamedQuery("getDPRuntimeByStartEnd")
		    .setParameter("dpName", dpName)
		    .setParameter("startTime", startTime)
		    .setParameter("endTime", endTime)
		    .getResultList();
	   }
	
	 @Transactional
	   public void  addDPProfile(DPProfile dpProfile){
		  logger.info("DP Profile name: "+dpProfile.getDpName());
		   em.persist(dpProfile);
		  logger.info(" DP Profile id: "+dpProfile.getId());
		  
	   }
	 @Transactional
	 public void updateDPProfile(DPProfile dpProfile) {
			// TODO Auto-generated method stub
		 logger.info("DP Profile name: "+dpProfile.getDpName());
		   em.merge(dpProfile);
		  logger.info(" DP Profile id: "+dpProfile.getId());
			
	}
	 
	 @Transactional
	   public void deleteDPProfileById(int id) {
		// TODO Auto-generated method stub
		 logger.info(" DP Profile id: "+id);
		 DPProfile profile = em.find(DPProfile.class, id);
		 em.remove(profile);
		   
	   }
	 @Transactional
	  public void  addDPRuntime(DPRuntime dpRuntime){
		  logger.debug("DP Profile name: "+dpRuntime.getDpName());
		   em.persist(dpRuntime);
		  logger.debug(" DP Profile id: "+dpRuntime.getId());
		  
	   }
	 
	 @Transactional
	  public List<DPRuntime>  getDPRuntimeByStartEndDate(Date startTime, Date endTime){
		  logger.debug("StartTime: "+startTime);
		  logger.debug("EndTime: "+endTime);
		  List<DPRuntime> list= new ArrayList<DPRuntime>();
		  return list;
		  
	   }
	 
}
